<?php 
	$pPageIsPublic = false;
	include '../_common.php';	
	$_SESSION["m1"]="page";
	$_SESSION["m2"]="feature";
	
	$objBac = new Picture();
	$objBac ->setUid(1);
	$objBac ->load();
	
	$objIn = new Picture();
	$objIn ->setUid(2);
	$objIn ->load();
	
	
if ($_GET['action']== 'del-bg') {
	if ($objBac ->isLoaded()) {
		$objBac ->removeImage('path');
		$message = "Background Site has been deleted.";
	}
		
}

if ($_GET['action']== 'del-in') {
	if ($objIn ->isLoaded()) {
		$objIn ->removeImage('path');
		$message = "Internal Banner has been deleted.";
	}
		
}

if (isset($_POST['update'])) {
	if ($objIn ->isLoaded()) {
		$objIn ->setAuto($_POST);
		$objIn ->uploadImage('ifile', 'path');
		
		$objIn ->getConnection();
		$objIn ->isbg = 2;
		$objIn ->update();
		$message = "Internal Banner has been updated.";
		
	}
}

if (isset($_POST['update2'])) {
	if ($objBac ->isLoaded()) {
		$objBac ->setAuto($_POST);
		$objBac ->uploadImage('ifile', 'path');
		
		$objBac ->getConnection();
		$objBac ->isbg = 1;
		$objBac ->update();
		$message = "Background has been updated.";
		
	}
}
	
?>
<?php include("header.php"); ?>
<?php
	$tabs 	= array('background-site' => 2, 'internal-banner' => 1);
	$selTab = $tabs[$_REQUEST['tab']] ? $tabs[$_REQUEST['tab']] : 0;
?>    
<style>label.status{display:inline-block; background-color:#fff !important; margin-top:-4px; padding-bottom:2px; cursor:default; } label.draft{color: red;} </style>
<script type="text/javascript">
$().ready(function(){
	$('#content-tabs').tabs({
		initial  : <?php echo $selTab ?>  
	});
});
</script>
<?php include("sidebar.php"); ?>
<div id="list">
	<h2>Feature Site</h2>
	<div id="content-tabs">
		<ul>
			<li><a href="#fragment-1"><span>Home Banners</span></a></li>
			<li><a href="#fragment-2"><span>Internal Banner</span></a></li>
			<li><a href="#fragment-3"><span>Site Background</span></a></li>
		</ul>
		<div id="fragment-1" >
<script type="text/javascript">
Shadowbox.init();  

$().ready(function(){
	var lExts = getFileExts('jpg|jpeg|gif|png').split("&");
	uploadImages('uploadify', {
		'scriptData'  : {'id' : '0'},
		'fileDesc'	  : 'Format Images ('+ lExts[1] +')',
        'fileExt'	  : lExts[0],
        'buttonImg'   : '../images/ico/upload-files.png',
        'height'	  : 16,
        'witdh'		  : 102,
        onAllComplete : function(data) {			  
			window.location.href = "<?php echo $_SERVER['PHP_SELF'] ?>?msg=Images Added.";
        } 
	});	

	$('#del').live('click', function(){
		 $(this).parent().parent().find('input:checkbox.checks').attr('checked', true).trigger('change');
		 delFileSelected(this);
	});

	$('#select-all').checkedToggle('ul.ui-sortable');

	$('#select-all').live('change', function() {
		$('input:checkbox.checks').trigger('change');
	});
	
	$('input:checkbox.checks').live('change', function(){
		$(this).parent().parent().parent().attr('class', this.checked ? "selected" : "");
	});

	$('ul.ui-sortable').admin_sortable("Picture");
	
});

 

function delFileSelected(btn) {

	var checked = $('input:checked.checks');
	 
	
	if (checked.length == 0) {
		Notify('Select a Banner.!',1);
		return false;
	} else {
		var items, li;		
		if (btn.id == "checked") {
			li = $('ul.ui-sortable > li.selected');
			items = checked.serialize();
		} else {
			li = $(btn).parent().parent().parent();
			items = $(btn).parent().parent().find('input:checkbox.checks').serialize();
		}
		items = decodeURIComponent(items);

		if (! confirm("You going to delete "+ li.length +" banner ?")){
			return false;
		} else {
			ajaxAdmin({
				data: items + "&action=file-delete",
				success: function(response) {
					if (response) {
						Notify(response, 0);
						li.fadeOut(300, function(){$(this).remove();});
					}	
				}
			});
		}					
	}
}

</script>			
			<fieldset style="padding-top: 0;" ><legend> Banner List </legend>
				<form action="<?php echo $_SERVER["PHP_SELF"]."" ?>" method="post" name="frmFilter" >
					<ul id="subnav" >
						<li class="noleft" ><input type="checkbox" name="select-all" id="select-all" /><label for="select-all" class="first-check" >Select All</label></li>
						<li><a href="javascript:void(0);" id="checked" onclick="delFileSelected(this)"  >Delete Selection</a></li>
			   			<li class="noborder"  ><?php include("filter.php"); ?></li>
			   			<li class="noborder noright" style="float:right;"   >
			   				<input type="file" name="uploadify" id="uploadify" />
        					<div id="fileQueue" ></div>
			   			</li>
					</ul>
			 	</form>
			 	<div id="list-boxes"  >
            		<ul class="ui-sortable">
<?php
	$objPic = new Picture();
	$objPic ->addOrder('orderId');
	$objPic ->addWhere("moduleId = 0 AND isbg = 0  AND status like '". $chkstatus ."%'  ");
	$objPic ->loadList();
    if ($objPic ->rMore()) {
    	while ($objItem = $objPic->rNext()) {    
                ?>                   
						<li id="recordsArray_<?php echo $objItem->id; ?>" class="" >
							<div class="pic-drag" >
								<?php echo $objItem->getImage(); ?>
								<label for="file-<?php echo $objItem->id ?>" ><input class="checks"   name="files[]" id="file-<?php echo $objItem->id;?>" type="checkbox" value="<?php echo $objItem->id;?>" />
												 <?php echo truncate_string($objItem->title, 12);?></label>
												 <label  class="status <?php echo $objItem->status=='Draft' ? 'draft' : ''; ?>">(<?php echo $objItem ->status  ?>)</label>
												 
                                <p class="itemsubnav" >
                                	<?php if(strlen($objItem->path)>0){ ?><a rel="shadowbox[files]" title="<?php echo $objItem->title ?>" href="<?php echo TZN_FILE_UPLOAD_URL_ADMIN.$objItem->path ?>">Preview</a><?php } ?>
                                    <a href="feature-banner-add.php?id=<?php echo $objItem->id ?>" title="Edit" >Edit</a>
                                    <a id="del" href="javascript:void(0);" title="" >Remove</a>
                                </p>
                            </div>
                        </li>	
<?php 	}	unset($objItem);
    } ?>                    					
            		</ul>            		
            		<div class="clear"></div>
  			</div>
			</fieldset>		
		</div>
		
		<div id="fragment-2" >
<?php
	if ($objIn ->isLoaded()):
?>		
	<form action="<?php echo $_SERVER["PHP_SELF"]."?tab=internal-banner" ?>" method="post" name="frm0" enctype="multipart/form-data"   >			
			<fieldset style="padding-top: 0;" ><legend> Internal Image </legend>
			<table cellpadding="0" cellspacing="0" class="table-form">
			   <tr>
			 	<th>Picture: </th>
			 	<td>
			 	<?php
			 		if (! $objIn ->path) {
			 			Tzn::qFile('ifile');
			 		} else { ?>
			 		<div class="img-border" style="width: 130px;" >
			 		 <?php echo $objIn ->getImage()  ?><br/>
			 		 	<a title="Delete Image" href="<?php echo $_SERVER['PHP_SELF'].'?action=del-in&tab=internal-banner' ?>" > <b>(x) delete </b> </a>
			 		</div>	
				<?php 	 			
			 		}
			 	?>
			 	</td>  
			   </tr>
			</table>
		</fieldset>
		<div style="margin-top:10px">
            <input type="submit" name="update"  value="Update" />
 		</div>
 	</form>
<?php endif;?>		
		
		
		</div>
		
		
		
		
		<div id="fragment-3" >
<?php
	if ($objBac ->isLoaded()):
?>		
			<script type="text/javascript" src="../js/extras/jscolor.js"></script>
	<form action="<?php echo $_SERVER["PHP_SELF"]."?tab=background-site" ?>" method="post" name="frm" enctype="multipart/form-data"   >			
			<fieldset style="padding-top: 0;" ><legend> Background Image </legend>
			<table cellpadding="0" cellspacing="0" class="table-form">
			   <tr>
			 	<th>Picture: </th>
			 	<td>
			 	<?php
			 		if (! $objBac ->path) {
			 			Tzn::qFile('ifile');
			 		} else { ?>
			 		<div class="img-border" style="width: 130px;" >
			 		 <?php echo $objBac ->getImage()  ?><br/>
			 		 	<a title="Delete Image" href="<?php echo $_SERVER['PHP_SELF'].'?action=del-bg&tab=background-site' ?>" > <b>(x) delete </b> </a>
			 		</div>	
				<?php 	 			
			 		}
			 	?>
			 	</td>  
			   </tr>
			   <tr>
            	<th >Background Color: (optional)</th>
					<td>
 					<?php $objBac->qText('color','','width:130px','class="color {hash:true, required: false}" id="color" '); ?>
 					<br /><span class="note-small">example: #ffffff </span>
					</td>
            	</tr>
			</table>
		</fieldset>
		<div style="margin-top:10px">
            <input type="submit" name="update2"  value="Update" />
 		</div>
 	</form>
<?php endif;?>		
		
		
		</div>
	</div>
</div>
<div class="clear"></div>    
<?php include("footer.php"); ?>
